﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#axis_type
    /// </summary>
    public class ChartAxis : IChartParam
    {
        public string Name { get { return "chxt"; } }

        public List<AxisLabelType> Axes { get; set; }

        public ChartAxis(AxisLabelType[] axisLabelTypes)
        {
            this.Axes = new List<AxisLabelType>();

            foreach (AxisLabelType axisLabelType in axisLabelTypes)
                this.Axes.Add(axisLabelType);
        }

        /// <summary>
        /// The default constructor
        /// </summary>
        public ChartAxis() { this.Axes = new List<AxisLabelType>(); }


        /// <summary>
        /// Render the API text
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (AxisLabelType axisLabelType in this.Axes)
                sb.Append(String.Format("{0},", axisLabelType.ToString()));

            // remove any trailing commas
            sb.Remove(sb.ToString().LastIndexOf(','), 1);

            return sb.ToString();
        }
    }
}
